﻿/*
=============================================================================
Author:魏宝辉通过CodeSmithe生成
CreatedTime:2012-8-10
Description:SenderMoney_Log.aspx.cs页面代码
=============================================================================	
*/

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using FTchina;
using FTchina.SMSServer;

public partial class SenderMoney_charge : System.Web.UI.Page
{
    string TableName = "SenderMoney_Log";//表名
    static string SqlWhere = " ( direction<>'Cost' and direction<>'CostReturn' ) ";//过滤条件
    string GetCountSql = "select count(id)  from SenderMoney_Log where " + SqlWhere;
    string SqlTable = "select *  from SenderMoney_Log where " + SqlWhere + "  order by id desc ";
    string ReturnPage = "SenderMoney_charge.aspx";
    FTchina.SearchQuery.QueryModel qm = new FTchina.SearchQuery.QueryModel();//实例化模型
    protected void Page_Load(object sender, EventArgs e)
    {
        FTchina.basic.CheckAdmin(this);
        FTchina.basic.ChkPoewr(this, FTchina.Api.htmlpath.GetCurrentPagePath());
        if (!IsPostBack)
        {

            if (qm.WorkPage != ReturnPage)
            {
                qm.TableName = TableName;
                qm.GetCountSql = GetCountSql;
                qm.GetTableSql = SqlTable;
                qm.ReturnPage = ReturnPage;
                qm.SqlWhere = SqlWhere;
                qm.WorkPage = ReturnPage;

            }

            bindData(qm);

            string act = FTchina.basic.FilterSQL(Request["act"]);
            switch (act)
            {

                case "add":
                    {
                        txbid.Text = "0";
                        txbid.Visible = false;

                        break;
                    }
                default:
                    {
                        txbid.Text = "0";
                        txbid.Visible = false;

                        break;
                    }

            }
            DdlBind();



        }

    }
    protected void DdlBind()
    {
        string sql = "select * from senderlist order by id desc";
        ddlsenderid.DataSource = shujuku.GetDataTable(sql);
        ddlsenderid.DataTextField = "sendername";
        ddlsenderid.DataValueField = "senderid";
        ddlsenderid.DataBind();
    }


    private void DataAdd()
    {
        FTchina.Models.SenderMoney_Log mSenderMoney_Log = new FTchina.Models.SenderMoney_Log();

        mSenderMoney_Log.Id = Convert.ToInt32(FTchina.basic.FilterSQL(txbid.Text));

        mSenderMoney_Log.SenderID = ddlsenderid.SelectedValue;

        mSenderMoney_Log.Money = Convert.ToDecimal(FTchina.basic.FilterSQL(txbmoney.Text));

        mSenderMoney_Log.Date = DateTime.Now;

        mSenderMoney_Log.Memo = FTchina.basic.FilterSQL(txbmemo.Text);

        mSenderMoney_Log.Direction = ddldirection.SelectedValue;

        mSenderMoney_Log.Smsguid = string.Empty;

        mSenderMoney_Log.Oper = FTchina.Library.MasterHelper.MasterName;

        bool flag = FTchina.BLL.SenderMoney_LogManager.AddSenderMoney_Log(mSenderMoney_Log) > 0;
        if (flag)
        {
            LogNet.LogBLL.info(mSenderMoney_Log.Oper + "为用户" + mSenderMoney_Log.SenderID + SMSServer.GetSenderNameByID(mSenderMoney_Log.SenderID) + "充值" + mSenderMoney_Log.Money + "注入SenderMoney_Log成功");
            FTchina.UImsg.PageRender(SMSServer.SenderMoneyCharge(mSenderMoney_Log.SenderID, mSenderMoney_Log.Money));
        }
        else
        {
            LogNet.LogBLL.info(mSenderMoney_Log.Oper + "为用户" + mSenderMoney_Log.SenderID + SMSServer.GetSenderNameByID(mSenderMoney_Log.SenderID) + "充值" + mSenderMoney_Log.Money + "注入SenderMoney_Log失败");
            FTchina.UImsg.PageRender(false);
        }
    }


    protected void btnSenderMoney_LogOk_Click(object sender, EventArgs e)
    {

        DataAdd();
    }


    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string senderid = ddlsenderid.SelectedValue;
        string SqlWhere = " ( direction<>'Cost' and direction<>'CostReturn' ) and  senderid='" + senderid + "' ";
        string GetCountSql = "select count(id) from SenderMoney_log where " + SqlWhere;
        string SqlTable = "select * from SenderMoney_log where " + SqlWhere + " order by id desc";
        string TableName = "SenderMoney_log";
        string ReturnPage = "SenderMoney_charge.aspx";

        qm.TableName = TableName;
        qm.GetCountSql = GetCountSql;
        qm.GetTableSql = SqlTable;
        qm.ReturnPage = ReturnPage;
        qm.SqlWhere = SqlWhere;

        //  basic.Log(qm.GetTableSql);
        // FTchina.SMSServer.QueryModel qm = new FTchina.SMSServer.QueryModel();



        bindData(qm);

    }





    #region gvList显示

    private void bindData(FTchina.SearchQuery.QueryModel qm)
    {

        int pCurrentPage = (FTchina.basic.SafeRequest(Request["page"]).Length > 0) ? Convert.ToInt32(FTchina.basic.SafeRequest(Request["page"])) : 1;
        int pageSize = 15;//每页的数据
        int AllCount = Convert.ToInt32(FTchina.shujuku.GetDataTable(qm.GetCountSql).Rows[0][0].ToString());//数据总条目数
        litpager.Text = FTchina.Api.Pager.GetPagerWithPageName(qm.GetTableSql, AllCount, pCurrentPage, pageSize, qm.ReturnPage);
        gvList.DataSource = FTchina.shujuku.ShowForPage(qm.TableName, qm.SqlWhere, pCurrentPage, pageSize);
        gvList.DataBind();
        //basic.Log(pCurrentPage);
        //basic.Log(qm.GetTableSql);
    }
    #endregion



    #region GridView等控件导出到Excel
    protected void btnexcel_Click(object sender, EventArgs e)
    {
        //将分页去除
        gvList.Width = Unit.Percentage(100);
        gvList.AutoGenerateColumns = false;
        gvList.AllowPaging = false;
        string GetDateSql = string.Format(SqlTable, TableName);
        DataSet ds = FTchina.shujuku.GetDataSet(GetDateSql);
        gvList.DataSource = ds;
        gvList.DataBind();

        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter writer = new System.Web.UI.HtmlTextWriter(stringWrite);
        gvList.RenderControl(writer);

        FTchina.Api.ToExcel.HtmlTableToExcel(stringWrite.ToString());
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        // 覆盖VerifyRenderingInServerForm方法，非常重要，否则系统会报错
        //base.VerifyRenderingInServerForm(control);
    }
    #endregion


}






